const openBluetoothAdapter = (obj) => {
    return new Promise((resolve, reject) => {
        obj.success = function (res) {
            resolve(res);
        };
        obj.fail = function (err) {
            reject(err);
        };
        uni.openBluetoothAdapter(obj);
    });
};
const closeBluetoothAdapter = (obj) => {
    return new Promise((resolve, reject) => {
        obj.success = function (res) {
            resolve(res);
        };
        obj.fail = function (res) {
            reject(res);
        };
        uni.closeBluetoothAdapter(obj);
    });
};
const onBluetoothAdapterStateChange = (obj) => {
    return new Promise((resolve, reject) => {
        obj.success = function (res) {
            resolve(res);
        };
        obj.fail = function (res) {
            reject(res);
        };
        uni.onBluetoothAdapterStateChange(obj);
    });
};
const getBluetoothAdapterState = (obj) => {
    return new Promise((resolve, reject) => {
        obj.success = function (res) {
            resolve(res);
        };
        obj.fail = function (res) {
            reject(res);
        };
        uni.getBluetoothAdapterState(obj);
    });
};
const startBluetoothDevicesDiscovery = (obj) => {
    return new Promise((resolve, reject) => {
        obj.success = function (res) {
            resolve(res);
        };
        obj.fail = function (res) {
            reject(res);
        };
        uni.startBluetoothDevicesDiscovery(obj);
    });
};
const stopBluetoothDevicesDiscovery = (obj) => {
    return new Promise((resolve, reject) => {
        obj.success = function (res) {
            resolve(res);
        };
        obj.fail = function (res) {
            reject(res);
        };
        uni.stopBluetoothDevicesDiscovery(obj);
    });
};
const getBluetoothDevices = (obj) => {
    return new Promise((resolve, reject) => {
        obj.success = function (res) {
            resolve(res);
        };
        obj.fail = function (res) {
            reject(res);
        };
        uni.getBluetoothDevices(obj);
    });
};
const getConnectedBluetoothDevices = (obj) => {
    return new Promise((resolve, reject) => {
        obj.success = function (res) {
            resolve(res);
        };
        obj.fail = function (res) {
            reject(res);
        };
        uni.getConnectedBluetoothDevices(obj);
    });
};
const onBluetoothDeviceFound = (obj) => {
    return new Promise((resolve, reject) => {
        obj.success = function (res) {
            resolve(res);
        };
        obj.fail = function (res) {
            reject(res);
        };
        uni.onBluetoothDeviceFound(obj);
    });
};
const createBLEConnection = (obj) => {
    return new Promise((resolve, reject) => {
        obj.success = function (res) {
            resolve(res);
        };
        obj.fail = function (res) {
            reject(res);
        };
        uni.createBLEConnection(obj);
    });
};
const closeBLEConnection = (obj) => {
    return new Promise((resolve, reject) => {
        obj.success = function (res) {
            resolve(res);
        };
        obj.fail = function (res) {
            reject(res);
        };
        uni.closeBLEConnection(obj);
    });
};
const getBLEDeviceServices = (obj) => {
    return new Promise((resolve, reject) => {
        obj.success = function (res) {
            resolve(res);
        };
        obj.fail = function (res) {
            reject(res);
        };
        uni.getBLEDeviceServices(obj);
    });
};
const getBLEDeviceCharacteristics = (obj) => {
    return new Promise((resolve, reject) => {
        obj.success = function (res) {
            resolve(res);
        };
        obj.fail = function (res) {
            reject(res);
        };
        uni.getBLEDeviceCharacteristics(obj);
    });
};
const readBLECharacteristicValue = (obj) => {
    return new Promise((resolve, reject) => {
        obj.success = function (res) {
            resolve(res);
        };
        obj.fail = function (res) {
            reject(res);
        };
        uni.readBLECharacteristicValue(obj);
    });
};
const writeBLECharacteristicValue = (obj) => {
    return new Promise((resolve, reject) => {
        obj.success = function (res) {
            resolve(res);
        };
        obj.fail = function (res) {
            reject(res);
        };
        uni.writeBLECharacteristicValue(obj);
    });
};
const notifyBLECharacteristicValueChange = (obj) => {
    return new Promise((resolve, reject) => {
        obj.success = function (res) {
            resolve(res);
        };
        obj.fail = function (res) {
            reject(res);
        };
        uni.notifyBLECharacteristicValueChange(obj);
    });
};
const onBLEConnectionStateChange = (obj) => {
    return new Promise((resolve, reject) => {
        obj.success = function (res) {
            resolve(res);
        };
        obj.fail = function (res) {
            reject(res);
        };
        uni.onBLEConnectionStateChange(obj);
    });
};
const onBLECharacteristicValueChange = (obj) => {
    return new Promise((resolve, reject) => {
        obj.success = function (res) {
            resolve(res);
        };
        obj.fail = function (res) {
            reject(res);
        };
        uni.onBLECharacteristicValueChange(obj);
    });
};
const reverseLookup = (obj) => (val) => {
    for (const k of Object.keys(obj)) {
        if (obj[k] === val) {
            return k;
        }
    }
    return 'UNKNOWN';
};
module.exports = {
    openBluetoothAdapter: openBluetoothAdapter,
    closeBluetoothAdapter: closeBluetoothAdapter,
    getBluetoothAdapterState: getBluetoothAdapterState,
    onBluetoothAdapterStateChange: onBluetoothAdapterStateChange,
    startBluetoothDevicesDiscovery: startBluetoothDevicesDiscovery,
    stopBluetoothDevicesDiscovery: stopBluetoothDevicesDiscovery,
    getBluetoothDevices: getBluetoothDevices,
    getConnectedBluetoothDevices: getConnectedBluetoothDevices,
    onBluetoothDeviceFound: onBluetoothDeviceFound,
    createBLEConnection: createBLEConnection,
    closeBLEConnection: closeBLEConnection,
    getBLEDeviceServices: getBLEDeviceServices,
    getBLEDeviceCharacteristics: getBLEDeviceCharacteristics,
    readBLECharacteristicValue: readBLECharacteristicValue,
    writeBLECharacteristicValue: writeBLECharacteristicValue,
    notifyBLECharacteristicValueChange: notifyBLECharacteristicValueChange,
    onBLEConnectionStateChange: onBLEConnectionStateChange,
    onBLECharacteristicValueChange: onBLECharacteristicValueChange
};
